﻿using System;
using Microsoft.ApplicationBlocks.Data;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Configuration;
using System.Data.SqlClient;

namespace DataAccess
{
    public class NhomSanPhamDAO
    {
        private static readonly String URL = ConfigurationSettings.AppSettings["Main.ConnectionString"];
        public NhomSanPhamDAO()
        {

        }

        public static DataSet GetAll()
        {
            return SqlHelper.ExecuteDataset(URL, CommandType.Text, "SELECT * FROM NhomSanPham");
        }

        public static void Delete(int id) 
        {
            SqlParameter[] sqlParameter = new SqlParameter[1];
            sqlParameter[0] = new SqlParameter("@MaNhomSanPham", id);
            SqlHelper.ExecuteNonQuery(URL, CommandType.Text, "DELETE FROM NhomSanPham WHERE MaNhomSanPham = @MaNhomSanPham", sqlParameter);
        }

        public static void Insert(string name)
        {
            SqlParameter[] sqlParameter = new SqlParameter[1];
            sqlParameter[0] = new SqlParameter("@TenNhomSanPham", name);          
            SqlHelper.ExecuteNonQuery(URL, CommandType.Text, "INSERT INTO NhomSanPham(TenNhomSanPham) VALUES(@TenNhomSanPham)", sqlParameter);
        }

        public static void Update(int id,string name)
        {
            SqlParameter[] sqlParameter = new SqlParameter[2];
            sqlParameter[0] = new SqlParameter("@TenNhomSanPham", name);            
            sqlParameter[1] = new SqlParameter("@MaNhomSanPham", id);
            SqlHelper.ExecuteNonQuery(URL, CommandType.Text, "UPDATE NhomSanPham SET TenNhomSanPham = @TenNhomSanPham WHERE MaNhomSanPham = @MaNhomSanPham", sqlParameter);
        }
        public static DataSet GetBy(int id)
        {
            SqlParameter[] sqlParameter = new SqlParameter[1];
            sqlParameter[0] = new SqlParameter("@MaNhomSanPham", id);
            return SqlHelper.ExecuteDataset(URL, CommandType.Text, "SELECT * FROM NhomSanPham WHERE MaNhomSanPham = @MaNhomSanPham", sqlParameter);
        }
    }
}
